'''
Company
'''

from tools.aivo_llm import AivoLLM

class Company:
    currentHumanCount = 0
    def __init__(self,id,name,config):
        self.id = id
        self.name = name
        self.services = {}
        self.servicellm = AivoLLM(config=config)

    #接受human和历史消息
    def serviceClockOn(self,human,history=[],template=""):
        Company.currentHumanCount += 0
        if human.id in self.services:
            raise Exception("service id " + human.id + "is exist")
        else:
            self.services[human.id] = human
            human.setQAChain(self.servicellm.qa_chain(history_message=history,template=template))

    def serviceClockOff(self,human):
        print(human.id)
        if human.id in self.services:
            Company.currentHumanCount -= 0
            self.services.pop(human.id)
        else:
            raise  Exception("service id " + id + "is not exist")

    def serviceById(self,service_id):
        if service_id in self.services:
            return self.services[service_id]
        else:
            raise Exception("service id " +  service_id + "is no exist")
        
    def info(self):
        services = {}
        for key,service in self.services.items():
            services[service.id] = service.info()
        return services